<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 
<head> 
<title>Scuola Media E. d'Arborea - Lamarmora </title> 
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> 
<meta name="description" content="Il sito della scuola secondaria superiore di Iglesias, in Sardegna" /> 
<meta name="keywords" content="scuola, iglesias, didattica, insegnamento, docenti" /> 
<link rel="stylesheet" href="andreas08.css" type="text/css" media="screen,projection" /> 
<link href="/css/themes/default.css" rel="stylesheet" type="text/css"/>
<link href="/css/themes/mac_os_x.css" rel="stylesheet" type="text/css"/>
<?php include $_ENV["DOCUMENT_ROOT"]."/js/prototype.php" ?>
<script type="text/javascript" src="/js/page.js"></script>
<script type="text/javascript" src="/js/window.js"></script>
<script type="text/javascript" src="/js/window_effects.js"></script>
<script type="text/javascript">
function repeating_switch(student, is_repeating){
	var rep = 0;
	if(is_repeating == 0){
		rep = 1;
	}
	var row = 'row'+student+'_field5';
	if($(row).innerHTML == "SI")
		rep = 0;
	else
		rep = 1;
	//alert(rep);
	var req = new Ajax.Updater({success: row}, 'update_student.php',
			  {
			    	parameters: {student: student, repeat: rep, action: 'switch'},
			  });
}

var new_address = true;

function change_phone(link,id_alunno){
	//alert("ID alunno in change2: "+id_alunno);
     //link.innerText e link.text sono stessa cosa, c'è differenza tra ie e firefox
    textname = "phn"+id_alunno;
    field_name = "p_inp"+id_alunno;
	if(link.innerText){
		testovecchio = link.innerText;
	}
	else{
		testovecchio = link.text;
	}
	//riscrivo il contenuto del div
	if(testovecchio == "Non presente")
		testovecchio = "";
	$(textname).innerHTML="<input type='text' style='border: 1px solid gray; font-size: 10px; width: 70%' id='"+field_name+"' value='"+testovecchio+"'> <input type='button' style='border: 1px solid; font-size: 10px' value='Registra' onclick=\"phone(\'"+field_name+"\', "+id_alunno+")\">";
}

function phone(field, student){
	//alert(rep);
	phone = $(field).value;
	var row = "phn"+student;
	var req = new Ajax.Updater({success: row}, 'update_student.php',
			  {
			    	parameters: {student: student, phone: phone, action: "phone"},
			  });
}

function change_address(link,id_alunno){
	//alert("ID alunno in change2: "+id_alunno);
     //link.innerText e link.text sono stessa cosa, c'è differenza tra ie e firefox
    textname = "add"+id_alunno;
    field_name = "a_inp"+id_alunno;
	if(link.innerText){
		testovecchio = link.innerText;
	}
	else{
		testovecchio = link.text;
	}
	//riscrivo il contenuto del div
	if(testovecchio == "Non presente")
		testovecchio = "";
	$(textname).innerHTML="<input type='text' style='border: 1px solid gray; font-size: 10px; width: 50%' id='"+field_name+"' value='"+testovecchio+"'> <input type='button' style='border: 1px solid; font-size: 10px' value='Registra' onclick=\"address(\'"+field_name+"\', "+id_alunno+")\">";
}

function address(field, student){
	//alert(rep);
	address = $(field).value;
	var row = "add"+student;
	var req = new Ajax.Updater({success: row}, 'update_student.php',
			  {
			    	parameters: {student: student, address: address, action: "address"},
			  });
}

var show_profile = function(id){
	var win = new Window({className: "mac_os_x",  width:400, height:250, zIndex: 100, resizable: true, title: "Profilo alunno ", showEffect:Effect.Appear, hideEffect: Effect.Fade, draggable:true, wiredDrag: true, url: "student_profile.php?sid="+id});	
	//win.getContent().update("<div style='font-weight: bold; font-size: 12px; text-align: center; margin-top: 20px' class='Titolo'>Funzione strumentale per la gestione e il monitoraggio del POF</div><div style='text-align: left; font-weight: normal; font-size: 11px; padding: 10px; margin-top: 20px; padding-bottom: 35px'><ul  style='margin-left: 20px;'><li style='list-style-type: disc;'>Gestione, revisione e monitoraggio del POF</li><li style='list-style-type: disc;'>Monitoraggio dei progetti extra-curricolo</li><li style='list-style-type: disc;'>Coordinamento delle funzioni strumentali</li></ul></div>");     
	win.showCenter(true);
};

</script>
</head> 
<body> 
<div id="container" > 
<div id="header"> 
<h1>Scuola Media E. d'Arborea - Lamarmora</h1> 
<h2>area riservata ai docenti</h2> 
</div> 
<?php include "navigation.php" ?>
<div id="content"> 
<h2 style="text-align: center"><?php print ($_SESSION['__classe__']->to_string()." - ". $_SESSION['__current_year__']->to_string()) ?></h2> 
<table style="width: 100%; margin-left: auto; margin-right: auto" cellpadding="0" cellspacing="0">
	<tr>
		<td colspan="5" style="text-align: center; border-width: 0px 0px 0px 0px; border-style: dotted; font-weight: bold; font-size: 12px">Elenco alunni (<?php print $res_alunni->num_rows ?>)</td>	
	</tr>
	<tr>
		<td style="width: 25%; text-align: center; font-weight: bold; border-width: 0px 0px 1px 0px; border-style: dotted">Nome e cognome</td>
		<td style="width: 15%; text-align: center; font-weight: bold; border-width: 0px 0px 1px 0px; border-style: dotted">Data nascita</td>
		<td style="width: 35%; text-align: center; font-weight: bold; border-width: 0px 0px 1px 0px; border-style: dotted">Indirizzo</td>
		<td style="width: 15%; text-align: center; font-weight: bold; border-width: 0px 0px 1px 0px; border-style: dotted">Telefono</td>
		<td style="width: 10%; text-align: center; font-weight: bold; border-width: 0px 0px 1px 0px; border-style: dotted">Ripetente</td>
	</tr>
	<?php 
	$background = "";
	$idx = 1;
	while($alunno = $res_alunni->fetch_assoc()){
		if(($idx % 2) == 0)	
			$background = "; background-color: #e8eaec";
		else
			$background = "";
		$ripetente = "NO";
		if($alunno['ripetente'] == 1)
			$ripetente = "SI";
			
		// estraggo l'indirizzo
		$address = "Non presente";
		$sel_add = "SELECT * FROM indirizzi_alunni WHERE id_alunno = ".$alunno['id_alunno'];
		$res_add = $db->execute($sel_add);
		if($res_add->num_rows > 0){
			$add = $res_add->fetch_assoc();
			if($add['indirizzo'] != "")
				$address = $add['indirizzo'];
		}
		
		// estraggo il telefono
		$phone = "Non presente";
		$sel_add = "SELECT * FROM indirizzi_alunni WHERE id_alunno = ".$alunno['id_alunno'];
		$res_add = $db->execute($sel_add);
		if($res_add->num_rows > 0){
			$add = $res_add->fetch_assoc();
			if($add['telefono1'] != "")
				$phone = $add['telefono1'];
		}
		
	?>
	<tr>
		<td id="row<?php print $alunno['id_alunno'] ?>_field1" style="width: 25%; text-align: left; padding-left: 20px; font-weight: normal; border-width: 0px 0px 0px 0px; border-style: solid<?php print $background ?>"><a href="#" style="font-weight: normal" onclick="show_profile(<?php print $alunno['id_alunno'] ?>)"><?php print ($alunno['cognome']." ".$alunno['nome']) ?></a></td>
		<td id="row<?php print $alunno['id_alunno'] ?>_field2" style="width: 15%; text-align: center; font-weight: normal; border-width: 0px 0px 0px 0px; border-style: solid<?php print $background ?>"><?php print format_date($alunno['data_nascita'], SQL_DATE_STYLE, IT_DATE_STYLE, "/") ?></td>
		<td style="width: 35%; text-align: center; font-weight: normal; border-width: 0px 0px 0px 0px; border-style: solid<?php print $background ?>"><span id="add<?php print $alunno['id_alunno'] ?>"><a href="#" id="row<?php print $alunno['id_alunno'] ?>_field3" onclick="change_address(this, <?php print $alunno['id_alunno'] ?>)" style="font-weight: normal; color: #303030"><?php print $address ?></a></span></td>
		<td style="width: 15%; text-align: center; font-weight: normal; border-width: 0px 0px 0px 0px; border-style: solid<?php print $background ?>"><span id="phn<?php print $alunno['id_alunno'] ?>"><a id="row<?php print $alunno['id_alunno'] ?>_field4" href="#" onclick="change_phone(this, <?php print $alunno['id_alunno'] ?>, event)" style="font-weight: normal; color: #303030"><?php print $phone ?></a></span></td>
		<td style="width: 10%; text-align: center; font-weight: normal; border-width: 0px 0px 0px 0px; border-style: solid<?php print $background ?>"><a id="row<?php print $alunno['id_alunno'] ?>_field5" href="#" onclick="repeating_switch(<?php print $alunno['id_alunno'] ?>, <?php print $alunno['ripetente'] ?>)" style="font-weight: normal; color: #303030"><?php print $ripetente ?></a></td>
	</tr>
	<?php 
		$idx++;
	}
	?>
</table>
<div class="splitcontentleft"> 
<p>&nbsp;</p>
</div> 
</div> 
<div id="subcontent"> 
<?php include 'smallbox.php'; ?>
<?php include "class_working.php" ?>
</div> 
<?php include "footer.php" ?>
</div> 
</body> 
</html>